﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Kalficom.Forms
{
    public partial class frmSystemParamtters : Form
    {
        public frmSystemParamtters()
        {
            InitializeComponent();
            conf.Icon(this);
        }

        Libraies.db db = new Libraies.db();
        Query.qry_system_parameter query = new Query.qry_system_parameter();

        private string getFile(string FileFilter)
        {
            OpenFileDialog ShowFileDialog = new OpenFileDialog();
            ShowFileDialog.Filter = FileFilter;
            String fileName = "";
            if (ShowFileDialog.ShowDialog() == DialogResult.OK) fileName = ShowFileDialog.FileName;
            return fileName;
        }

        private string getDirectory()
        {
            FolderBrowserDialog ShowFolderDialog = new FolderBrowserDialog();
          
            String folderName = "";
            if (ShowFolderDialog.ShowDialog() == DialogResult.OK) folderName = ShowFolderDialog.SelectedPath;
            return folderName;
        }

        private void btnBrowser1_Click(object sender, EventArgs e)
        {
            textBox1.Text = getFile("Text File (*.txt)|*.txt");
        }

        private void btnBrowser6_Click(object sender, EventArgs e)
        {
            textBox2.Text = getDirectory();
        }

        private void btnBrowser7_Click(object sender, EventArgs e)
        {
            textBox3.Text = getFile("Batch File (*.bat)|*.bat");
        }

        private void frmSystemParamtters_Load(object sender, EventArgs e)
        {
            textBox1.Text = db.ExecuteScalar(string.Format(query.scalar, 1));
            textBox2.Text = db.ExecuteScalar(string.Format(query.scalar, 2));
            textBox3.Text = db.ExecuteScalar(string.Format(query.scalar, 3));

            this.WindowState = FormWindowState.Maximized;
        }

        private void btnMainMenu_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(new Libraies.msg().saveMsg, new Libraies.msg().captionMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                db.ExecuteNonQuery(string.Format(query.update, db.SqlString(textBox1.Text), 1));
                db.ExecuteNonQuery(string.Format(query.update, db.SqlString(textBox2.Text), 2));
                db.ExecuteNonQuery(string.Format(query.update, db.SqlString(textBox3.Text), 3));
            }
        }
    }
}
